//
//  BySuperLottoVC.m
//  caipiao_ios
//
//  Created by mc on 2018/7/12.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "BySuperLottoVC.h"
#import "ByCoreViewSegmentControl.h"
#import "BySuperLottoHeadView.h"
#import "BySuperSectionView.h"
#import "BySomeCirclesView.h"
#import "BySuperHandleViews.h"
#import "ByLotteryAlgorithmHandle.h"
#import "ByDottedLineView.h"
#import "BySuperBileDragTableView.h"
#import "BySuperLottoListVC.h"
#import "BySuperLottoCirclesView.h"



@interface BySuperLottoVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) ByCoreViewSegmentControl *segTitle;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) BySuperLottoHeadView *headView;
@property (nonatomic, strong) BySuperLottoHeadView *headView2;

@property (nonatomic, strong) NSMutableArray *redDataArray;
@property (nonatomic, strong) NSMutableArray *blueDataArray;
@property (nonatomic, assign) NSInteger type;

@property (nonatomic, strong) BySuperHandleViews *handleViews;
@property (nonatomic, strong) BySuperBileDragTableView *bileDragView;
@property (nonatomic, strong) BySuperHandleViews *bileDragHandleViews;
@property (nonatomic, assign) NSInteger count;

@property (nonatomic, strong) NSMutableArray *hisArray;
@property (nonatomic, strong) ByNetModel *newestModel;

@end

@implementation BySuperLottoVC

- (NSMutableArray *)hisArray{
    if (_hisArray == nil) {
        _hisArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _hisArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self addLeftBackBarButtonItem];
    self.title = @"大乐透";
    [self initViews];
    
    self.type = 0;
    
    [self loadRandomData];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    [self performSelector:@selector(deselect) withObject:nil afterDelay:0.2];
}

- (void)deselect{
    self.redDataArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:35];
    self.blueDataArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:12];
    [self updateViewsState];
    [self.tableView reloadData];
    
    
    self.bileDragView.redOneArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:35];
    self.bileDragView.blueOneArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:12];
    self.bileDragView.redTwoArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:35];
    self.bileDragView.blueTwoArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:12];
    [self.bileDragView reloadData];
    [self updateBileDragViewsState];
}

- (void)loadRandomData{
    self.redDataArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:35];
    self.blueDataArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:12];
    [self updateViewsState];
    [self.tableView reloadData];
    
    
    ByNetModel *netModel = [[ByNetModel alloc] init];
    [ByNumberApi getLottoPrizeHistory:netModel success:^(ByNetBaseResult *result) {
        
        SLog(@"大乐透历史 = %@", result.data);
        NSDictionary *dicitonary = result.data[@"data"];
        if (dicitonary[@"newest"] && [dicitonary[@"newest"] isKindOfClass:[NSDictionary class]]) {
            self.newestModel = [[ByNetModel alloc] initContentWithDic:dicitonary[@"newest"]];
        }
        
        for (NSDictionary *dic in dicitonary[@"his"]) {
            ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
            [self.hisArray addObject:netModel];
        }
        ByNetModel *hisNewModel = [self.hisArray firstObject];
        
        self.headView.netModel = hisNewModel;
        self.headView2.netModel = hisNewModel;
        
        self.headView.topLabel.text = [NSString stringWithFormat:@"第%@期 %@截止投注",self.newestModel.phaseno, [NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:self.newestModel.localendtime.integerValue]]];
        self.headView.bottomLabel.text = [NSString stringWithFormat:@"第%@期",hisNewModel.number];
        self.headView.circlesView.itemsAry = [ByLotteryAlgorithmHandle getModelsArrayWithNumString:hisNewModel.result_num];
        
        self.headView2.topLabel.text = [NSString stringWithFormat:@"第%@期 %@截止投注",self.newestModel.phaseno, [NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:self.newestModel.localendtime.integerValue]]];
        self.headView2.bottomLabel.text = [NSString stringWithFormat:@"第%@期",hisNewModel.number];
        self.headView2.circlesView.itemsAry = [ByLotteryAlgorithmHandle getModelsArrayWithNumString:hisNewModel.result_num];
        
        if (self.newestModel.phaseno.length == 0){
            self.headView.topLabel.hidden = YES;
            self.headView2.topLabel.hidden = YES;
        }
        
        
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showOnlyText:result.msg];
        
        self.headView.topLabel.hidden = YES;
        self.headView.bottomLabel.hidden = YES;
        self.headView2.topLabel.hidden = YES;
        self.headView2.bottomLabel.hidden = YES;
    }];
}


- (NSMutableArray *)redDataArray{
    if (_redDataArray == nil) {
        _redDataArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _redDataArray;
}

- (NSMutableArray *)blueDataArray{
    if (_blueDataArray == nil) {
        _blueDataArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _blueDataArray;
}

-(void)initViews{
    
    self.segTitle = [[ByCoreViewSegmentControl alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 39)];
    [self.view addSubview:self.segTitle];
    [self _initData];
    
    
    
    self.view.backgroundColor = BY_BACKGROUND_COLOR;
    self.tableView = [[UITableView alloc] init];
    self.tableView.backgroundColor = BY_BACKGROUND_COLOR;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        if (@available(ios 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(39);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-50);
        } else {
            make.top.equalTo(self.view).offset(39);
            make.bottom.equalTo(self.view).offset(-50);
        }
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    BySuperLottoHeadView *headView = [[BySuperLottoHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 90)];
    self.tableView.tableHeaderView = headView;
    self.headView = headView;
    
    BySuperHandleViews *handleViews = [[BySuperHandleViews alloc] init];
    [self.view addSubview:handleViews];
    [handleViews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(@50);
        make.top.equalTo(self.tableView.mas_bottom).offset(0);
    }];
    self.handleViews = handleViews;
    
    
    
    handleViews.sureBlock = ^(){
        if ([ByLotteryAlgorithmHandle getSelectedDataWithArray:self.redDataArray].count < 5 || [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.blueDataArray].count < 2) {
             [ByCoreToolAlert showOnlyText:@"红球最少选择5个，篮球最少选择2个"];
            return ;
        }else{
            
            
            BySuperLottoListVC *vc = [[BySuperLottoListVC alloc] init];
            ByNetModel *netModel = [[ByNetModel alloc] init];
            netModel.count = self.count;
            
            NSMutableArray *redSelectArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.redDataArray];
            NSMutableArray *blueSelectArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.blueDataArray];
            NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:1];
            [tempArray addObject:redSelectArray];
            [tempArray addObject:blueSelectArray];
            netModel.dataArray = [tempArray copy];
            
            if (redSelectArray.count == 5 && blueSelectArray.count == 2) {
                netModel.type = 0;
            }else if (redSelectArray.count > 5 && blueSelectArray.count == 2){
                netModel.type = 1;
            }else if (redSelectArray.count == 5 && blueSelectArray.count > 2){
                netModel.type = 2;
            }else if (redSelectArray.count > 5 && blueSelectArray.count > 2){
                netModel.type = 3;
            }
            
            NSMutableArray *selectedArray = BY_APPDELEGATE.selectedArray;
            [selectedArray addObject:netModel];
            BY_APPDELEGATE.selectedArray = selectedArray;
            vc.newestModel = self.newestModel;
            [self by_normalPush:vc hasNavi:YES];
        }
       
    };
    
    handleViews.clearBlock = ^(){
        self.handleViews.countLabel.text = @"1";
        self.redDataArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:35];
        self.blueDataArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:12];
        [self.tableView reloadData];
        [self updateViewsState];
    };
    
    handleViews.pauseBlock = ^(){
        self.handleViews.countLabel.text = @"1";
        self.redDataArray = [ByLotteryAlgorithmHandle getRandomAllDataWithCount:35 selectedCount:5];
        self.blueDataArray = [ByLotteryAlgorithmHandle getRandomAllDataWithCount:12 selectedCount:2];
        [self updateViewsState];
        
        [self.tableView reloadData];
        
    };
    
    handleViews.updateBlock = ^(){
         [self updateViewsState];
    };
    
    
    self.bileDragView = [[BySuperBileDragTableView alloc] init];
    [self.view addSubview:self.bileDragView];
    [self.bileDragView  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        if (@available(ios 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(39);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-50);
        } else {
            make.top.equalTo(self.view).offset(39);
            make.bottom.equalTo(self.view).offset(-50);
        }
    }];
    __weak typeof(self) weakSelf = self;
    self.bileDragView.updateBlock = ^(){
        [weakSelf updateBileDragViewsState];
    };
    
    
    BySuperLottoHeadView *headView2 = [[BySuperLottoHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 90)];
    self.bileDragView.tableHeaderView = headView2;
    self.headView2 = headView2;
    self.bileDragView.hidden = YES;
    
    
    BySuperHandleViews *bileDragHandleViews = [[BySuperHandleViews alloc] init];
    [self.view addSubview:bileDragHandleViews];
    [bileDragHandleViews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(@50);
        make.top.equalTo(self.tableView.mas_bottom).offset(0);
    }];
    bileDragHandleViews.hidden = YES;
    self.bileDragHandleViews = bileDragHandleViews;
    
    
    
    bileDragHandleViews.sureBlock = ^(){
       
        NSMutableArray *redOneArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.redOneArray];
        NSMutableArray *redtwoArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.redTwoArray];
        NSMutableArray *blueOneArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.blueOneArray];
        NSMutableArray *bluetwoArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.blueTwoArray];
        
        if (redOneArray.count > 0 && redtwoArray.count > 1 && bluetwoArray.count > 1 && blueOneArray.count == 1 ) {
           
            BySuperLottoListVC *vc = [[BySuperLottoListVC alloc] init];
            ByNetModel *netModel = [[ByNetModel alloc] init];
            
            netModel.count = self.count;
            netModel.type = 4;//胆拖
            NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
            [dataArray addObject:redOneArray];
            [dataArray addObject:redtwoArray];
            [dataArray addObject:blueOneArray];
            [dataArray addObject:bluetwoArray];
            netModel.dataArray = [dataArray copy];
            
            NSMutableArray *selectedArray = BY_APPDELEGATE.selectedArray;
            [selectedArray addObject:netModel];
            BY_APPDELEGATE.selectedArray = selectedArray;
            vc.newestModel = self.newestModel;
            [self by_normalPush:vc hasNavi:YES];
            
        }else{
            
            [ByCoreToolAlert showOnlyText:@"投注不符合要求，请检查"];
        }
    };
    
    bileDragHandleViews.clearBlock = ^(){
        
        self.bileDragView.redOneArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:35];
        self.bileDragView.blueOneArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:12];
        self.bileDragView.redTwoArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:35];
        self.bileDragView.blueTwoArray = [ByLotteryAlgorithmHandle getOriginalDataWithCount:12];
        [self.bileDragView reloadData];
        [self updateBileDragViewsState];
        
    };
    
    bileDragHandleViews.pauseBlock = ^(){
    
        NSMutableArray *redArray = [ByLotteryAlgorithmHandle getRandomAllDataWithCount:35 oneSelectedCount:4 anotherSelectedCount:2];
        NSMutableArray *blueArray = [ByLotteryAlgorithmHandle getRandomAllDataWithCount:12 oneSelectedCount:1 anotherSelectedCount:2];
        self.bileDragView.redOneArray = [redArray firstObject];
        self.bileDragView.redTwoArray = [redArray lastObject];
        self.bileDragView.blueOneArray= [blueArray firstObject];
        self.bileDragView.blueTwoArray =[blueArray lastObject];
        [self.bileDragView reloadData];
        [self updateBileDragViewsState];
    };
    
    bileDragHandleViews.updateBlock = ^(){
        [self updateBileDragViewsState];
    };
    

}
- (void)updateBileDragViewsState{

    NSMutableArray *redOneArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.redOneArray];
    NSMutableArray *redtwoArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.redTwoArray];
    NSMutableArray *blueOneArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.blueOneArray];
    NSMutableArray *bluetwoArray = [ByLotteryAlgorithmHandle getSelectedDataWithArray:self.bileDragView.blueTwoArray];
    
    if (redOneArray.count > 0 && redtwoArray.count > 1 && bluetwoArray.count > 1 && blueOneArray.count == 1) {
         NSInteger count = [ByLotteryAlgorithmHandle getCountWithSelectedData:redtwoArray leastNumber:5 - redOneArray.count] * [ByLotteryAlgorithmHandle getCountWithSelectedData:bluetwoArray leastNumber:1];
        
        self.bileDragHandleViews.countLabel.text = [NSString stringWithFormat:@"%ld注", count];
        self.bileDragHandleViews.valueLabel.text = [NSString stringWithFormat:@"%.f元", count * 2.0];
        self.count = count;
        
    }else{
        
        self.bileDragHandleViews.valueLabel.text = [NSString stringWithFormat:@"0元"];
        self.bileDragHandleViews.countLabel.text = @"0注";
        self.count = 0;
    }
}


- (void)updateViewsState{
    
    if ([[ByLotteryAlgorithmHandle getSelectedDataWithArray:self.redDataArray] count] > 4 && [[ByLotteryAlgorithmHandle getSelectedDataWithArray:self.blueDataArray] count] > 1) {
        NSInteger count = [ByLotteryAlgorithmHandle getCountWithSelectedData:self.redDataArray leastNumber:5] * [ByLotteryAlgorithmHandle getCountWithSelectedData:self.blueDataArray leastNumber:2];
        
        self.handleViews.countLabel.text = [NSString stringWithFormat:@"%ld注", count];
        self.handleViews.valueLabel.text = [NSString stringWithFormat:@"%.f元",count * 2.0];
        self.count = count;
        
    }else{
        
        self.handleViews.valueLabel.text = [NSString stringWithFormat:@"0元"];
        self.handleViews.countLabel.text = @"0注";
        self.count = 0;
        
    }
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
        static NSString *cellIdentifier = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            
            UILabel *line = [[UILabel alloc] init];
            [cell addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell).offset(0);
                make.right.equalTo(cell).offset(0);
                make.bottom.equalTo(cell).offset(0);
                make.height.mas_equalTo(@1);
            }];
            line.backgroundColor = BY_LINE_COLOR;
        }
        
        for (UIView *view in cell.contentView.subviews) {
            [view removeFromSuperview];
        }
    
        cell.contentView.backgroundColor = BY_BACKGROUND_COLOR;
    
      UIView *backgroundView = [[UIView alloc] init];
      [cell.contentView addSubview:backgroundView];
      [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cell.contentView).offset(5);
        make.right.equalTo(cell.contentView).offset(-5);
        make.top.equalTo(cell.contentView).offset(0);
        make.bottom.equalTo(cell.contentView).offset(0);
      }];
      backgroundView.layer.cornerRadius = 5;
      backgroundView.layer.masksToBounds = YES;
     backgroundView.backgroundColor = [UIColor whiteColor];
    
    BySuperSectionView *sectionView = [[BySuperSectionView alloc] init];
    [backgroundView addSubview:sectionView];
    [sectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(10);
        make.top.equalTo(backgroundView).offset(10);
        make.right.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@20);
    }];
    
    sectionView.selectBlock= ^(){
        ByWebViewController *vc = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@/Wanfajiesao/jiesao?type=2001",BOYE_WEB_BASE_URL]];
        vc.titleString = @"大乐透玩法说明";
        [self by_normalPush:vc hasNavi:YES];
    };
    
    
    BySomeCirclesView *redView = [[BySomeCirclesView alloc] init];
    [backgroundView addSubview:redView];
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(sectionView.mas_bottom).offset(10);
        make.height.mas_equalTo(@([BySomeCirclesView getHeighWithItemsAry:[self.redDataArray copy]]));
    }];
    redView.themeColor = BY_THEME_COLOR;
    redView.itemsAry = [self.redDataArray copy];
    redView.selectBlock = ^(NSInteger index){
        ByNetModel *netModel = [self.redDataArray objectAtIndex:index];
        netModel.selected = !netModel.selected;
        [self updateViewsState];
        [self.tableView reloadData];
    };
    
    ByDottedLineView *line = [[ByDottedLineView alloc] init];
    line.direction = DottedLineViewDirectionHorizontalFromRight;
    line.lineColor = [UIColor lightGrayColor];
    line.lengthPattern = @[@4, @3];
    [backgroundView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(redView.mas_bottom).offset(0);
        make.height.mas_equalTo(@1);
    }];
    
    BySuperSectionView *sectionView1 = [[BySuperSectionView alloc] init];
    [backgroundView addSubview:sectionView1];
    [sectionView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(10);
        make.top.equalTo(line.mas_bottom).offset(10);
        make.right.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@19);
    }];
    sectionView1.playView.hidden = YES;
    sectionView1.noteLabel.text = @"最少选择2个";
    sectionView1.titleLabel.textColor = BY_Blue_COLOR;
    sectionView1.titleLabel.text = @"篮球(后区)";
    
   
    BySomeCirclesView *blueView = [[BySomeCirclesView alloc] init];
    [backgroundView addSubview:blueView];
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(sectionView1.mas_bottom).offset(10);
        make.height.mas_equalTo(@([BySomeCirclesView getHeighWithItemsAry:[self.blueDataArray copy]]));
    }];
    blueView.themeColor = BY_Blue_COLOR;
    blueView.itemsAry = [self.blueDataArray copy];
    blueView.selectBlock = ^(NSInteger index){
        ByNetModel *netModel = [self.blueDataArray objectAtIndex:index];
        netModel.selected = !netModel.selected;
        [self updateViewsState];
        [self.tableView reloadData];
    };
   
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [BySomeCirclesView getHeighWithItemsAry:self.redDataArray] + [BySomeCirclesView getHeighWithItemsAry:self.blueDataArray] + 40 * 2;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
}


#pragma mark -- 初始化数据 --
- (void)_initData{
    self.segTitle.sectionTitles = @[@"普通投注",@"胆拖投注"];
    self.segTitle.backgroundColor = [UIColor whiteColor];
    self.segTitle.font = FONT(14);
    self.segTitle.scrollEnabled = YES;
    self.segTitle.textColor = [UIColor blackColor];
    self.segTitle.selectedTextColor = BY_THEME_COLOR;
    self.segTitle.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    self.segTitle.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
    self.segTitle.selectionIndicatorHeight = 3;
    self.segTitle.segmentEdgeInset = UIEdgeInsetsMake(0, 0, 0, 0);
    __weak typeof(self) weakSelf = self;
    [self.segTitle setIndexChangeBlock:^(NSInteger index) {
        weakSelf.type = index;
        if (index == 0) {
            weakSelf.tableView.hidden = NO;
            weakSelf.bileDragView.hidden = YES;
            weakSelf.handleViews.hidden = NO;
            weakSelf.bileDragHandleViews.hidden = YES;
        }else{
            weakSelf.tableView.hidden = YES;
            weakSelf.bileDragView.hidden = NO;
            weakSelf.handleViews.hidden = YES;
            weakSelf.bileDragHandleViews.hidden = NO;
        }
    }];
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 38, SCREEN_WIDTH, 1)];
    lbl.backgroundColor = [UIColor colorWithHexString:@"dbdbdb"];
    [self.segTitle addSubview:lbl];
    [self.view addSubview:self.segTitle];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
